package com.codi.bus.core.dao.impl;

import com.codi.base.dao.plugin.page.PageView;
import com.codi.base.dao.v2.GeneratedBaseDaoImpl;
import com.codi.bus.core.dao.OrganBankDao;
import com.codi.bus.core.domain.OrganBank;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @author lvgo
 * @version 1.0
 * @Description: 机构银行卡
 * @date 2018/5/9 14:32
 */
@Repository("organBankDao")
public class OrganBankDaoImpl extends GeneratedBaseDaoImpl<OrganBank> implements OrganBankDao {

    @Override
    public List<OrganBank> selectByTradeAccount(String tradeAccount) {
        return this.findList(generateStatement("selectByTradeAccount"), tradeAccount);
    }

    @Override
    public List<OrganBank> selectUsableByProfileId(Long profileId) {
        return this.findList(generateStatement("selectUsableByProfileId"), profileId);
    }
    @Override
    public List<OrganBank> selectAllListByProfileId(Long profileId) {
        return this.findList(generateStatement("selectAllListByProfileId"), profileId);
    }
    @Override
    public OrganBank getByProfileIdAndBankNo(Long profileId, String bankNo) {
        Map<String, Object> params = new HashMap<>();
        params.put("profileId", profileId);
        params.put("bankNo", bankNo);
        return this.getObject(generateStatement("getByProfileIdAndBankNo"), params);
    }

    @Override
    public List<OrganBank> getAll(String profileName,String state,Integer pageIndex,Integer pageSize) {
        Map<String, Object> params = new HashMap<>();
        PageView pageView = getPageView(pageIndex, pageSize);
        params.put("pageView", pageView);
        params.put("profileName", profileName);
        params.put("state", state);
        return this.findList(generateStatement("getAll"), params);
    }

    @Override
    public int insertOne(OrganBank organBank) {
        return this.insert(generateStatement("insertSelective"), organBank);
    }


    /**
     * 获取分页信息
     *
     * @param pageIndex
     * @param pageSize
     * @return
     */
    public PageView getPageView(Integer pageIndex, Integer pageSize) {
        PageView pageView = null;
        if (pageIndex == null) {
            pageView = new PageView(1);
        } else {
            pageView = new PageView(pageIndex);
        }
        if (pageSize == null) {
            pageSize = 10;
        }
        pageView.setPageSize(pageSize);
        return pageView;
    }
}
